<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>easyCMS</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="/resource/layuimini/lib/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/resource/layuimini/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
  <div class="layuimini-main">
    <table class="layui-hide" id="listTable" lay-filter="listTable"></table>
  </div>
</div>
<script src="/resource/layuimini/lib/layui/layui.js" charset="utf-8"></script>
<script>
  let _where = [];
  let _height = 800;
  let _width = 800;
  layui.use(['form', 'table'], function () {
    let $ = layui.jquery,
            form = layui.form,
            table = layui.table;
    _height = $(window).height();
    _width = $(window).width();
    table.render({
      elem: '#listTable'
      ,url:'/admin/role/roleListData'
      ,toolbar: '#toolbarDemo'
      ,defaultToolbar: false
      ,method:'post'
      ,page: false
      ,cols: [[
        {field:'name',title: '角色名称',width:250}
        ,{field:'created_at',width:250, title: '添加时间'}
        ,{field:'bar',title: "操作", width: "200", align: 'center', templet: '#bar1'}

      ]]
    });
    table.on('tool(listTable)', function (obj) {
      let data = obj.data
      let layEvent = obj.event
      if (layEvent === 'edit') {
        parent.layer.open({
          type: 2,
          title: "修改角色",
          area: ['900px', (_height-100)+'px'],
          content: '/admin/role/roleEdit?id=' + data.id
        });
      }
      else if (layEvent === 'del') {
        parent.layer.confirm('确定删除该角色吗？', {
          title: "删除该角色",
          btn: ['确定', '取消']//按钮
        }, function (index) {
          $.post("/admin/role/roleDelete", "id=" + data.id, function (data) {
            parent.layer.alert(data.msg,function (index) {
              if (data.code == 0) {
                table.reload('listTable', {});
              }
              parent.layer.closeAll();
            });
          }, "json");
        });
      }
    });
    table.on('toolbar(listTable)', function (obj) {
      let layEvent = obj.event
      if (layEvent === 'add') {
        parent.layer.open({
          type: 2,
          title: "增加角色",
          area: ['900px', (_height-100)+'px'],
          content: '/admin/role/roleAdd'
        });
      }

    });
  });
</script>
<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
  </div>
</script>
<script type="text/html" id="bar1">
  <a class="layui-btn layui-btn-xs " lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-xs layui-btn-danger " lay-event="del">删除</a>
</script>

</body>
</html>